package com.zhiwang.planet.ui.loginv2

import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProviders
import com.zhiwang.planet.R
import com.zhiwang.planet.databinding.ActivityLoginFillSmsBinding
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.mvvm.viewmodel.loginv2.WxLoginViewModel
import com.zhiwang.planet.ui.BaseActivity
import com.zhiwang.planet.util.AppUtil
import com.zhiwang.planet.util.TokenManager
import com.zhiwang.planet.util.Utils
import kotlinx.android.synthetic.main.activity_login_fill_sms.*
import javax.inject.Inject

class LoginFillSmsActivity : BaseActivity() {

    lateinit var viewModel: WxLoginViewModel

    @Inject
    lateinit var restApi: RestApi


    override fun initInjection() {

        userComponent(this)
                .inject(this)

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = DataBindingUtil.setContentView<ActivityLoginFillSmsBinding>(this, R.layout.activity_login_fill_sms)
        setSupportActionBar(toolbar)
        viewModel = ViewModelProviders.of(this).get(WxLoginViewModel::class.java)
        viewModel.context = this
        viewModel.restApi = restApi
        viewModel.errHandler = this::onError
        val userPhone = intent.getStringExtra("phone")
        viewModel.phone.value = userPhone
        viewModel.username.value = userPhone
        binding.lifecycleOwner = this
        binding.viewModel = viewModel
        AppUtil.getDeviceId {
            viewModel.imei = it
            TokenManager.saveDevice(it)
        }

        Utils.setStatusBar(this,false,false)
        Utils.setStatusTextColor(true,this)
    }
}